package com.franklin.java.configuration.sql.run.ui;

import com.franklin.java.api.ui.jpanel.AbstractComponent;
import com.franklin.java.api.ui.jpanel.checkbox.MultipleForOneCheckBox;
import com.franklin.java.configuration.sql.run.JdbcConsoleState;
import com.franklin.java.entity.sql.JdbcConsoleType;
import com.franklin.java.utils.ProjectUtils;
import com.intellij.openapi.project.Project;
import com.intellij.ui.TitledSeparator;
import com.intellij.ui.components.JBLabel;
import com.intellij.util.ui.FormBuilder;

import javax.swing.*;
import java.util.Arrays;

/**
 * @author Franklin
 * @since 2021/9/26 17:01
 */
public class JdbcConsoleComponent extends AbstractComponent {

    private final Project project;
    private JPanel mainPanel;
    private MultipleForOneCheckBox checkBox;

    public JdbcConsoleComponent(Project project) {
        this.project = project;
        this.checkBox = new MultipleForOneCheckBox(
            JdbcConsoleType.getNames(),
            JdbcConsoleState.getConsole(project)
        );
        this.checkBox.addTail("                                                         ");

        this.mainPanel = FormBuilder.createFormBuilder()
            .addComponent(new TitledSeparator("Mybatis Sql Running Console"),1)
            .addComponent(new JBLabel("Which console do you want to use ?"),1)
            .addComponent(this.checkBox,1)
            .getPanel();
    }

    public String getSelectedJdbcConsole(){
        return this.checkBox.getSelectItem();
    }

    @Override
    public JComponent getMainPanel() {
        return this.mainPanel;
    }
}
